package com.mynovamobile.android;

import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class MNMUserDefaults {
	private final String PREF_NAME = "User Defaults";
	private SharedPreferences userData;
	private Editor editor;
	private static MNMUserDefaults instance = null;
	private static Context callingContext;
	private MNMUserDefaults(Context context) {
		userData = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		editor = userData.edit();
	}
	
	public static MNMUserDefaults getInstance(Context context) {
		if (instance == null) {
			instance = new MNMUserDefaults(context);
		}
		callingContext = context;
		return instance;
	}
	
	public String getPrimaryFullName() {
		return userData.getString("PRIMARY_FULLNAME", null);
	}
	
	public String getPrimaryEmail() {
		return userData.getString("PRIMARY_EMAIL", null);
	}
	
	public String getPrimaryClassification() {
		return userData.getString("PRIMARY_CLASSIFICATION", null);
	}
	
	public String getMNMUserID() {
		return userData.getString("MNM_UID", null);
	}
	
	public String getLDAPUsername() {
		return userData.getString("LDAP_USERNAME", null);
	}
	
	public String getLDAPPassword() {
		return userData.getString("LDAP_PASSWORD", null);
	}
	
	public String getStudentID() {
		return userData.getString("STUDENT_ID", null);
	}
	
	public String getNovasisPIN() {
		return userData.getString("NOVASIS_PIN", null);
	}
	
	public String getWildcardID() {
		return userData.getString("WILDCARD_ID", null);
	}
	
	public String getWildcardPassword() {
		return userData.getString("WILDCARD_PASSWORD", null);
	}
	
	/*
	 * Begin mutator methods
	 */
	public MNMUserDefaults setPrimaryFullName(String primaryFullName) {
		editor.putString("PRIMARY_FULLNAME", primaryFullName).commit();
		return instance;
	}
	
	public MNMUserDefaults setPrimaryEmail(String primaryEmail) {
		editor.putString("PRIMARY_EMAIL", primaryEmail).commit();
		return instance;
	}
	
	public MNMUserDefaults setPrimaryClassification(String primaryClassification) {
		editor.putString("PRIMARY_CLASSIFICATION", primaryClassification).commit();
		return instance;
	}
	
	public MNMUserDefaults setMNMUserID(String MNMUserID) {
		editor.putString("MNM_UID", MNMUserID).commit();
		return instance;
	}
	
	public MNMUserDefaults setLDAPUsername(String LDAPUsername) {
		editor.putString("LDAP_USERNAME", LDAPUsername).commit();
		return instance;
	}
	
	public MNMUserDefaults setLDAPPassword(String LDAPPassword) {
		editor.putString("LDAP_PASSWORD", LDAPPassword).commit();
		return instance;
	}
	
	public MNMUserDefaults setStudentID(String studentID) {
		editor.putString("STUDENT_ID", studentID).commit();
		return instance;
	}
	
	public MNMUserDefaults setNovasisPIN(String novasisPin) {
		editor.putString("NOVASIS_PIN", novasisPin).commit();
		return instance;
	}
	
	public MNMUserDefaults setWildcardID(String wildcardID) {
		editor.putString("WILDCARD_ID", wildcardID).commit();
		return instance;
	}
	
	public MNMUserDefaults setWildcardPassword(String wildcardPassword) {
		editor.putString("WILDCARD_PASSWORD", wildcardPassword).commit();
		return instance;
	}	
	
	public Map<String, ?> getAllData() {
		return userData.getAll();
	}
	
	public boolean contains(String key) {
		return userData.contains(key);
	}
}
